package com.eascs.crm.nsEditDetail.service;

import com.eascs.app.dao.PageResult;
import com.eascs.app.dao.SqlPageQuery;
import com.eascs.crm.nsEditDetail.dao.NsEditDetailDao;
import com.eascs.crm.nsEditDetail.entity.ManagementTdInfoEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ManagementTdInfoService {

	@Autowired
	NsEditDetailDao nsDao;

	public boolean insert(ManagementTdInfoEntity info) {
		return nsDao.insert(info) > 0;
	}

	public boolean delete(String id) {
		return nsDao.execute("UPDATE management_td_info t SET t.is_del='Y' WHERE t.id=?", id) > 0;
	}

	public boolean update(ManagementTdInfoEntity info) {
		return nsDao.updateById(info) > 0;
	}

	public ManagementTdInfoEntity queryById(String id) {
		return nsDao.findEntity("SELECT * FROM management_td_info t WHERE t.id=?", ManagementTdInfoEntity.class, id);
	}

	public List<ManagementTdInfoEntity> list(String loanapplyNo) {
		String sql = "SELECT * FROM management_td_info t WHERE t.loanapply_no=? AND t.is_del='N'";
		return nsDao.findEntitys(sql, ManagementTdInfoEntity.class, loanapplyNo);
	}

	public PageResult<Object[]> page(String loanapplyNo, int pageNo) {
		String sql = "SELECT  t.id, t.td_year, t.fz_tot, t.net_price,t.year_money FROM management_td_info t WHERE t.loanapply_no=? AND t.is_del='N'";

		SqlPageQuery<Object[]> sqlPageQuery = new SqlPageQuery<>(Object[].class, 10, pageNo);
		sqlPageQuery.addParam(loanapplyNo);
		sqlPageQuery.setQuerySql(sql);


		return nsDao.findDataWithPage(sqlPageQuery);
	}

	public PageResult<Object[]> page(String loanapplyNo) {
		return this.page(loanapplyNo, 0);
	}
}
